﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DeviceInfoManage.BusinessLogicLayer;

public partial class DeRepairUpdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["adminUserName"] == null)
            {
                Response.Redirect("login.aspx");
            }

            /*根据设备编号得到设备各个字段的信息并添入个控件中*/
            hidRecordId.Value = Request.QueryString["repairId"];
            repairManage rd = new repairManage();
            rd = rd.GetModel(Int32.Parse(hidRecordId.Value));
            this.DeviceName.Text = rd.deviceUser;
            this.DeviceDpt.SelectedValue = rd.departmentName;
            this.txtWHSJ.Text = rd.repairTime.ToShortDateString();
            this.ddlErrType.Text = rd.errType;
            this.DeviceModel.Text = rd.deviceModel;
            this.DeviceSerialNumber.Text = rd.deviceSerialNumber;
            this.deviceNumber.Text = rd.propertySerialNumber;
            this.txtReStation.Text = rd.repairStation.ToString();
            this.DeviceMemo.Text = rd.errDetail;
        }
    }
    protected void Btn_Update_Click(object sender, EventArgs e)
    {
        /*建立一个记录对象，然后传入各个字段的属性值，最后调用插入函数执行添加*/

        repairManage device = new repairManage();
        device.repairId = int.Parse(hidRecordId.Value);
        device.deviceUser = this.DeviceName.Text;
        device.departmentName = this.DeviceDpt.SelectedValue;
        device.repairTime = DateTime.Parse(this.txtWHSJ.Text);
        device.errType = this.ddlErrType.SelectedValue;
        device.deviceModel = this.DeviceModel.Text;
        device.deviceSerialNumber = this.DeviceSerialNumber.Text;
        device.propertySerialNumber = this.deviceNumber.Text;
        device.repairStation = this.txtReStation.Text;
        device.errDetail = this.DeviceMemo.Text;
        /*插入函数返回添加是否成功，如果失败，ErrMessage中保存了错误信息*/
        if (device.Update(device) != -1)
            Response.Write("<script>alert('新送修信息更新成功!');</script>");//location.href='MaintRecordRegister.aspx';
        else
            Response.Write("<script>alert('更新失败!');</script>");
    }

    protected void Btn_Back_Click(object sender, EventArgs e)
    {
        Response.Redirect("DeRepairList.aspx");
    }
}
